﻿using System;

namespace SoftwareConsulting.BI11.NumericalMethods.ComplexNumbers
{        
    public class ComplexMath
    {
        public static Random RndObject = new Random(DateTime.UtcNow.Millisecond);

        public const double MachineEpsilon = 5E-16;
        public const double MaxRealNumber = 1E300;
        public const double MinRealNumber = 1E-300;

        public static double RandomReal()
        {
            double r = 0;
            lock (RndObject) { r = RndObject.NextDouble(); }
            return r;
        }
        public static int RandomInteger(int N)
        {
            int r = 0;
            lock (RndObject) { r = RndObject.Next(N); }
            return r;
        }
        public static double Sqr(double X)
        {
            return X * X;
        }
        public static double AbsComplex(ComplexNumber z)
        {
            double w;
            double xabs;
            double yabs;
            double v;

            xabs = Math.Abs(z.X);
            yabs = Math.Abs(z.Y);
            w = xabs > yabs ? xabs : yabs;
            v = xabs < yabs ? xabs : yabs;
            if (v == 0)
                return w;
            else
            {
                double t = v / w;
                return w * Math.Sqrt(1 + t * t);
            }
        }
        public static ComplexNumber Conj(ComplexNumber z)
        {
            return new ComplexNumber(z.X, -z.Y);
        }
        public static ComplexNumber CSqr(ComplexNumber z)
        {
            return new ComplexNumber(z.X * z.X - z.Y * z.Y, 2 * z.X * z.Y);
        }
    }
}
